using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Plugin.Sns.Scene;
using System;
namespace MicroMsg.Manager
{
	public class SnsPageScene
	{
		private string strUserName;
		private NetSceneSnsTimeLine sceneT;
		private NetSceneSnsUserPage sceneU;
		private SnsPageResponse response = new SnsPageResponse();
		private SnsPageSceneCallBack onPageCallBack;
		private bool isLoading;
		public SnsPageScene(string userName, SnsPageSceneCallBack snsPageSceneCallBack_0)
		{
			if (userName == SnsPageMgr.TimeLineUserName)
			{
				this.sceneT = new NetSceneSnsTimeLine(new SnsTimeLineCallBack(this.onTimeLinePageResponse));
			}
			else
			{
				this.sceneU = new NetSceneSnsUserPage(new SnsUserPageCallBack(this.onUserPageResponse));
			}
			this.strUserName = userName;
			this.onPageCallBack = snsPageSceneCallBack_0;
		}
		public bool getFirstPage(string strFirstPageMd5 = null)
		{
			if (this.isLoading)
			{
				return false;
			}
			this.isLoading = true;
			EventCenter.postEvent(EventConst.ON_MGR_SNSPAGE_REFRESH_PAGE_START, this.strUserName, null);
			this.response.type = (string.IsNullOrEmpty(strFirstPageMd5) ? PageRspType.firstPage : PageRspType.firstPageVerify);
			if (this.sceneT != null)
			{
				return this.sceneT.getFirstPage(strFirstPageMd5);
			}
			return this.sceneU.getFirstPage(this.strUserName, strFirstPageMd5);
		}
		public bool getNextPage(ulong maxID, ulong minID = 0uL, uint LastRequestTime = 0u)
		{
			if (this.isLoading)
			{
				return false;
			}
			this.isLoading = true;
			EventCenter.postEvent(EventConst.ON_MGR_SNSPAGE_REFRESH_PAGE_START, this.strUserName, null);
			this.response.type = ((LastRequestTime == 0u) ? PageRspType.nextPage : PageRspType.nextPagVerify);
			if (this.sceneT != null)
			{
				return this.sceneT.getNextPage(maxID, minID, LastRequestTime);
			}
			return this.sceneU.getNextPage(this.strUserName, maxID, minID, LastRequestTime);
		}
		public void onTimeLinePageResponse(int retCode, SnsTimeLineResponse timelineRsp)
		{
			this.isLoading = false;
			EventCenter.postEvent(EventConst.ON_MGR_SNSPAGE_REFRESH_PAGE_END, this.strUserName, null);
			if (timelineRsp == null)
			{
				this.onPageCallBack(null);
				return;
			}
			this.response.nRetCode = retCode;
			this.response.strFirstPageMd5 = timelineRsp.FirstPageMd5;
			this.response.objList = timelineRsp.ObjectListList;
			this.response.pageRequestTime = timelineRsp.NewRequestTime;
			this.response.total = 0;
			this.onPageCallBack(this.response);
		}
		public void onUserPageResponse(int retCode, SnsUserPageResponse userPageRsp)
		{
			this.isLoading = false;
			EventCenter.postEvent(EventConst.ON_MGR_SNSPAGE_REFRESH_PAGE_END, this.strUserName, null);
			if (userPageRsp == null)
			{
				this.onPageCallBack(null);
				return;
			}
			this.response.nRetCode = retCode;
			this.response.strFirstPageMd5 = userPageRsp.FirstPageMd5;
			this.response.objList = userPageRsp.ObjectListList;
			this.response.pageRequestTime = userPageRsp.NewRequestTime;
			this.response.total = (int)userPageRsp.ObjectTotalCount;
			this.onPageCallBack(this.response);
		}
		public bool isPageLoading()
		{
			return this.isLoading;
		}
		public bool isFirstPageLoading()
		{
			return this.isLoading && (this.response.type == PageRspType.firstPage || this.response.type == PageRspType.firstPageVerify);
		}
	}
}
